﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using DAL;

namespace PeisongWeb.admin
{
    public partial class sellerCompanyList : adminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("FD", 1))
                {
                    drpBind();
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }
        // 企业类别
        void drpBind()
        {
            DataTable dt = logic.sysCode.sellerTypeList();
            ddl_Type.DataSource = dt;
            ddl_Type.DataBind();
        }
        void rptBind()
        {
            StringBuilder where = new StringBuilder();
            where.Append("isCheck=1 and [type]='1' ");
            if (txt_companyName.Text.Trim() != "")
                where.AppendFormat("and company like '%{0}%'", txt_companyName.Text.Trim());
            if (ddl_Type.SelectedValue != "")
                where.AppendFormat("and sellerType = '{0}'", ddl_Type.SelectedValue.Trim());
            where.AppendFormat(" and isDel=0");
            DataSet ds = logic.company.select(where.ToString(), "companyId desc", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }
        protected void lbtn_Search_Click(object sender, EventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = 0;
            rptBind();
        }

        public string GetSellername(string xm)
        {
            DataRow rows = DAL.DbHelper.ExecuteSqlDataRow("select * from sysCode where bm='16' and xm='"+xm+"'");
            if (rows != null)
            {
                return rows["name"].ToString();
            }
            else { return string.Empty; }
        }

        /// <summary>
        /// 判断该供应商今天是否已考核过
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int ByDt(int id)
        {
            DataTable dt = logic.assessment.Bydt(id);
            return dt.Rows.Count;
        }

        protected void link_CompanyCheck_Command(object sender, CommandEventArgs e)
        {
            int companyId = 0;
            int.TryParse(e.CommandArgument.ToString().Split(',')[0],out companyId);
            int types = 0;
            int.TryParse(e.CommandArgument.ToString().Split(',')[1],out types);

            //if (ByDt(companyId) > 0)
            //{
            //    Library.Script.ClientMsg("该供应商今天已考核过");
            //}
            //else
            //{
                Response.Redirect("sellerAssessmentEdit.aspx?id="+companyId+"&types="+types);
           // }
        }
    }
}
